/********************************************************************************
 *    Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH    *
 *                                                                              *
 *              This software is distributed under the terms of the             *
 *              GNU Lesser General Public Licence (LGPL) version 3,             *
 *                  copied verbatim in the file "LICENSE"                       *
 ********************************************************************************/
#ifndef MYDETECTORMAPPINGTASK_H
#define MYDETECTORMAPPINGTASK_H

// #include "HiMusicUnpackedData.h"
// #include "HiMusicMappedData.h"
#include "FairTask.h"
#include "TClonesArray.h"
#include <map>

// class HiMusicUnpackedData; // 输入结构（包含 PXI, FEE 等）
// class HiMusicMappedData;   // 输出结构（映射后的数据）

class HiMusicMappingTask : public FairTask
{
public:
    HiMusicMappingTask();
    virtual ~HiMusicMappingTask();

    virtual InitStatus Init();
    virtual InitStatus ReInit();
    virtual void Exec(Option_t *option) ;
    virtual void SetParContainers();
    virtual void Finish() ;

    void SetMapFile(const TString &filename) { fMapYamlFile = filename; }

private:
    TString fMapYamlFile;

    TClonesArray *fUnpackedDataArray = nullptr; // 输入
    TClonesArray *fMappedArray = nullptr;       // 输出

    // 存储映射关系: key = (PXI,FEE) -> value = (detectorName, detID)
    std::map<std::pair<uint8_t, uint8_t>, std::pair<TString, uint8_t>> fMapTable;

    void LoadMappingFromYAML(); // 读取映射表文件


    HiMusicMappingTask(const HiMusicMappingTask&);
    HiMusicMappingTask operator=(const HiMusicMappingTask&);
    ClassDef(HiMusicMappingTask, 1);
};

#endif
